#include "Testing.h"

Testing::Testing()
{
    image = NULL;
    counter = 0;
}

Testing::~Testing()
{}

int Testing::load(QString path)
{
    if(path.isEmpty()) {
        std::cout << "The path specified does not exist.\n";
        return -1;
    }

    lastLoadPath.clear();
    lastLoadPath.append(path);

    return image->load(path);
}

int Testing::save(QString path)
{
    if(image->isNull()) {
        std::cout << "No image to save. Please load an image first.\n";
        return -1;
    }
    else if (path.isEmpty()){
        std::cout << "The path specified does not exist.\n";
        return -1;
    }

    if(path != "") {

        lastSavePath.clear();
        lastSavePath.append(path);

        return image->save(path);
    }
    else {
        QFileInfo newPath (lastLoadPath);

        QString suffix (newPath.completeSuffix());
        QString defaultPath (newPath.absolutePath());
        defaultPath.append(newPath.baseName());

        char buffer[5];
        sprintf(buffer, "_out_%d", counter);

        defaultPath.append(buffer);
        defaultPath.append(suffix);

        counter++;

        return image->save(defaultPath);
    }
}

int Testing::process()
{
    return 0;
}

void Testing::endProgram()
{
    std::cout << "\n Ending program.\n";
    exit(0);
}

int Testing::showImage(/*int argc, char** argv*/)
{
//    QApplication a(argc, argv);

//    QImage img ("im13.jpeg");
    MainWindow w (0, image);

    w.show();

    return 0;
//    return a.exec();
}

